﻿using AntMovement.Core.Model;
using Prism.Events;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Regions;

namespace AntMovement.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        private object _userWindow;

        public object UserWindow
        {
            get { return _userWindow; }
            set { SetProperty(ref _userWindow, value); }
        }
        private string _title = "运动控制卡项目测试";
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }
        private IContainerProvider _containerProvider;

        public MainWindowViewModel(IContainerProvider containerProvider, IEventAggregator eventAggregator)
        {
            _containerProvider = containerProvider;
            var regionViewRegistry = containerProvider.Resolve<IRegionViewRegistry>();
            regionViewRegistry.RegisterViewWithRegion("MenuContentRegion", typeof(Views.EnumTree));
            regionViewRegistry.RegisterViewWithRegion("ResectionContentRegion", typeof(Views.StatusBar));
            eventAggregator.GetEvent<MessageEvent>().Subscribe(sender => {
                if (sender != null && sender.Data.ContainsKey("View"))
                {
                    UserWindow = sender.Data["View"];
                }
            }, arg => arg.Code == 200);
        }
    }
}
